<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>入库登记页面</title>
		<link rel="stylesheet" href="/bootstrap/bootstrap-5.3.3-dist/css/bootstrap.min.css" />
		<link rel="stylesheet" href="/css/manufactureCss/Set_production_process_items.css" />
		<style type="text/css">
			
		</style>
	</head>
	<body>
		<div class="panel product">
			<div class="panel-heading hhead">
				<nav aria-label="breadcrumb">
				  <ol class="breadcrumb">
				  	<span style="color: blue;">您正在做的业务是：</span>
				    <li class="breadcrumb-item"><a href="#">库存管理</a></li>
				    <li class="breadcrumb-item"><a href="#">入库管理</a></li>
				    <li class="breadcrumb-item active" aria-current="page">入库登记（责任人控制）</li>
				  </ol>
				</nav>
				<div>
					<p><small>当前等待登记的入库登记总数：<span style="color: red;" id="num">2</span>例</small></p>
				</div>
			</div>
			<form id="searchForm">
				<input type="hidden" id="page" name="pageNum" value="1">
				<input type="hidden" id="pageSize" name="pageSize" value="5">
				<input type="hidden" name="checkTag" value="1">
				<input type="hidden" name="gatherTag" value="2">
			</form>
			<div class="panel-body bbody">
				<table id="tab" >
					<thead>
						<tr style="background-color: #e8e8e8;">
							<td>入库单编号</td>
							<td>入库理由</td>
							<td>入库详情理由</td>
							<td>登记时间</td>
							<td>总件数</td>
							<td>总金额（元）</td>
							<td>登记</td>
						</tr>
					</thead>
					<tbody id="template">

					</tbody>
				</table>
			</div>

			<div class="panel-footer ffooter">
				<div id="footerDiv">
					<label style="font-weight: 700;">总数：<span style="color: red;" id="footNum1">5</span>例&nbsp;&nbsp;&nbsp;&nbsp;
						当前第<span style="color: red;" id="pageNum1">5</span>页&nbsp;&nbsp;&nbsp;&nbsp;
						共<span style="color: red;" id="pagesNum1">6</span>页&nbsp;&nbsp;&nbsp;&nbsp;
					</label>
				</div>
			</div>
		</div>
		<script type="text/javascript" src="/js/jquery-3.7.0.min.js"></script>
		<script type="text/javascript" src="/bootstrap/bootstrap-5.3.3-dist/js/bootstrap.bundle.min.js"></script>
		<script type="text/javascript" src="/js/common.js"></script>
		<script type="text/javascript">
			$(function (){
				initialArchiveTable(1);
			})
			function initialArchiveTable(pageNum){
				$("#page").val(pageNum)
				let json = formDateToJson("searchForm");
				$.ajax({
					url: "/s-gather/initialWarehousingTable",
					type: "POST",
					data: json,
					contentType: "application/json",
					dataType: "json",
					success: function (Page) {
						console.log(Page)
						$("#num").html(Page.total);
						$("#footNum1").html(Page.total);
						$("#pageNum1").html(pageNum);
						let pages = Math.ceil(Page.total / 5);
						$("#pagesNum1").html(pages);
						params = {
							"First": 1,
							"Previous": Page.current > 1 ? Page.current - 1 : 1,
							"Next": Page.current < pages ? Page.current + 1 : pages,
							"Last": pages
						};
						console.log(params);

						$("#a0").attr("href", "javascript:initialArchiveTable(" + params.First + ")")
						if(pageNum <= 2){
							a1 = 1;
							a2 = 2;
							a3 = 3;
						}else if(pageNum >= pages - 1){
							a1 = pageNum - 2;
							a2 = pageNum - 1;
							a3 = pageNum;
						}else {
							a1 = pageNum - 1;
							a2 = pageNum;
							a3 = pageNum + 1;
						}
						$("#a1").attr("href", "javascript:initialArchiveTable(" + a1 + ")")
						$("#a1").html(a1)
						a1 == pageNum? $("#a1").addClass("active") : $("#a1").removeClass("active")
						$("#a2").attr("href", "javascript:initialArchiveTable(" + a2 + ")")
						$("#a2").html(a2)
						a2 == pageNum? $("#a2").addClass("active") : $("#a2").removeClass("active")
						a3 == pageNum? $("#a3").addClass("active") : $("#a3").removeClass("active")
						$("#a3").attr("href", "javascript:initialArchiveTable(" + a3 + ")")
						$("#a3").html(a3)
						$("#a4").attr("href", "javascript:initialArchiveTable(" + params.Last + ")")
						tbody = $("#template");
						tbody.empty();

						var files = Page.list;
						FileArr = ["gatherId", "reason","reasonexact", "registerTime", "amountSum", "costPriceSum","Audit"]
						for (var i = 0; i < files.length; i++) {
							var tr = document.createElement("tr");
							var product = files[i];
							for (var k in FileArr) {
								var td = document.createElement("td");
								console.log(product[FileArr[k]])
								if(FileArr[k] == "Audit"){
									let b = "<a href='javascript:registration("  + files[i]["id"]+ ")' class='btn btn-outline-success ' >登记</a>";
									td.innerHTML = b;
									tr.appendChild(td);
								}else {
									td.innerHTML = product[FileArr[k]] != undefined ? product[FileArr[k]] : "";
									tr.appendChild(td);
								}
							}
							tbody[0].appendChild(tr);
						}
						sessionStorage.clear();
					},
					error: function (e) {

					}
				})
			}
			function registration(id) {

				sessionStorage.setItem("id", id);
				window.location.href="/s-gather/Warehouse_Receving_Registration_sub";
			}

		</script>
	</body>
</html>

